package com.jadesoft.stock.util;

import java.util.Calendar;

import org.apache.commons.httpclient.HttpClient;

import com.jadesoft.stock.entity.StockSubscript;

public class StockUtil {
	public static String[] splitStock(String stock) {

		String[] r = stock.replace(")", "").replace("(", "-").split("-");
		if (r.length == 3) {
			return new String[] { r[0] + "(" + r[1] + ")", r[2] };
		} else
			return r;
	}

	public static String compileSymbolName(StockSubscript subs) {
		return subs.getStockName() + "(" + subs.getStockSymbol() + ")";
	}

	public static void main(String[] args) {
		Calendar calendar = Calendar.getInstance(Constants.TIME_ZONE_CHINA);
		System.out.println(calendar);
		System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
	}

	/**
	 * 判断股票交易日 1:周一--周五 2:读取配置文件
	 * 
	 * @return
	 */
	public static boolean isDayTrading() {
		return !StockUtil.isNotDayTrading();
	}

	public static boolean isNotDayTrading() {
		Calendar calendar = Calendar.getInstance(Constants.TIME_ZONE_CHINA);
		int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
		return dayOfWeek == Constants.DAY_OF_WEEK_SATURDAY
				|| dayOfWeek == Constants.DAY_OF_WEEK_SUNDAY;
	}

	public static HttpClient getHttpClient() {
		HttpClient client = new HttpClient();
		// client.getHostConfiguration().setProxy("128.96.172.23", 808);
		return client;
	}
}
